from toee import *

def san_dialog( attachee, triggerer ):
	if attachee.map == 5123:
		triggerer.begin_dialog( attachee, 1 )
	else:
		triggerer.begin_dialog( attachee, 40 )
	return SKIP_DEFAULT

def san_heartbeat( attachee, triggerer ):
	if (attachee.map == 5123):
		attachee.object_flag_unset(OF_OFF)
	if ((attachee.map == 5121) and (game.global_flags[996] == 0 )):
		attachee.object_flag_set(OF_OFF)
	if ((attachee.map == 5121) and (game.global_flags[996] == 1 )):
		attachee.object_flag_unset(OF_OFF)
	return RUN_DEFAULT

def san_enter_combat( attachee, triggerer ):
	for npc in game.obj_list_vicinity( pc.location, OLC_NPC ):
		if npc.name == 14455:
			target = find_pc_near(npc)
			npc.attack(target)
	return RUN_DEFAULT

def find_pc_nearest( obj ):
	distance = 1000000
	target = OBJ_HANDLE_NULL
	for pc in game.obj_list_vicinity( obj.location, OLC_PC ):
		if (obj.distance_to(pc) < distance):
			distance = obj.distance_to(pc)
			target = pc
	if (pc != OBJ_HANDLE_NULL):
		return pc
	return OBJ_HANDLE_NULL